﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Aandelendelen.Obs
{
	public class ObjectFormatter
	{
		public static string GetFormattedDate(DateTime dateTime)
		{
			string dayFormat = (dateTime.Date == DateTime.Today ? "'Vandaag'" : dateTime.Date == DateTime.Today.AddDays(-1) ? "'Gisteren'" : "dd-MM-yyyy");
			string timeFormat = (dateTime.TimeOfDay == TimeSpan.Zero ? "" : ", HH:mm:ss");

			return dateTime.ToString(dayFormat + timeFormat);

			//if (dateTime.TimeOfDay == TimeSpan.Zero)
			//{
			//    if (dateTime.Date == DateTime.Today)
			//        return "Vandaag";
			//    else
			//        return dateTime.ToString("dd-MM-yyyy");
			//}
			//else
			//    if (dateTime.Date == DateTime.Today)
			//        return dateTime.ToString("'Vandaag', HH:mm:ss");

			//return dateTime.ToString("dd-MM-yyyy, HH:mm:ss");
		}

		public static string GetFormattedDateTimeOnly(DateTime dateTime)
		{
			return dateTime.ToString("HH:mm:ss");
		}

		public static string GetProfitPercentageString(decimal buy, decimal current)
		{
			decimal percentage = Calculator.GetProfitPercentage(buy, current);

			return GetPercentageString(percentage);
		}

		public static string GetPercentageString(decimal number)
		{
			return number.ToString("+#0.00'%';-#0.00'%'");
		}

		public static string GetNumberOfStocks(decimal number)
		{
			return number.ToString("F4");
		}

		public static string GetCurrencyString(decimal number, bool nulIsEmpty)
		{
			if (nulIsEmpty == false || number != 0)
				return number.ToString("c2");

			return "";
		}

		public static string GetRateString(decimal number, bool nulIsEmpty)
		{
			if (nulIsEmpty == false || number != 0)
				return number.ToString("c3");

			return "";
		}

		public static string GetRateString(decimal number)
		{
			return GetRateString(number, false);
		}

		public static string GetCurrencyString(decimal number)
		{
			return GetCurrencyString(number, false);
		}

		public static string GetCurrencyString(object o, bool nulIsEmpty)
		{
			return GetCurrencyString(o == null ? 0 : (decimal)o, nulIsEmpty);
		}

		public static string GetCurrencyString(object o)
		{
			return GetCurrencyString(o, false);
		}

		public static string CurrentIp
		{
			get
			{
				string ip = null;

				if (HttpContext.Current != null)
					if (HttpContext.Current.Request != null)
						if (HttpContext.Current.Request.ServerVariables != null)
							ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

				return ip;
			}
		}
	}
}